import React from 'react';
import { Cascader } from 'antd';
import { formatMessage } from 'umi';
import classNames from 'classnames';
import Text from './_components/Text';
import styles from './index.less';

const Index = (props) => {
  const {
    placeholder = formatMessage({ id: '请选择' }), // 选择框默认文字
    showSearch = true,

    options = [
      {
        value: 'zhejiang',
        label: '浙江',
        children: [
          {
            value: 'hangzhou',
            label: '杭州',
            children: [
              {
                value: 'xihu',
                label: '西湖',
                disabled: false,
              },
            ],
          },
        ],
      },
      {
        value: 'jiangsu',
        label: '江苏',
        children: [
          {
            value: 'nanjing',
            label: '南京',
            children: [
              {
                value: 'zhonghuamen',
                label: '中华门',
              },
            ],
          },
        ],
      },
    ],
    value,

    disabled,

    ...rest
  } = props;

  if (!Object.keys(props).includes('value')) {
    return 'DEPRECATED';
  }

  if (disabled && disabled.render) {
    return <Text value={value} options={options} render={disabled.render} />;
  }

  return (
    <span className={classNames(styles.col24, styles.componentWrapper)}>
      <Cascader
        placeholder={placeholder}
        showSearch={showSearch}
        options={options}
        {...rest}
        disabled={!!disabled}
        value={value}
      />
    </span>
  );
};

Index.displayName = 'Cascader';
export default Index;
